 #define QT_NO_DEBUG_OUTPUT

#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QDeclarativeContext>

#include "boardgui.h"
#include "movegenerator.h"
#include "movemaker.h"
#include "search.h"

//// message handling
//void myMessageOutput(QtMsgType type, const char *msg)
//{
//    switch (type) {
//    case QtDebugMsg:
//        fprintf(stderr, "Debug: %s\n", msg);
//        break;
//    case QtWarningMsg:
//        fprintf(stderr, "Warning: %s\n", msg);
//        break;
//    case QtCriticalMsg:
//        fprintf(stderr, "Critical: %s\n", msg);
//        break;
//    case QtFatalMsg:
//        fprintf(stderr, "Fatal: %s\n", msg);
//        abort();
//    }
//}


Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    // ### chess engine setup (board, movegen, movemake, gui, search) ###
    Board board;
    MoveGenerator moveGenerator(board); // here only given to boardGUI.. not needed actually

//    qInstallMsgHandler(myMessageOutput);
    Search search(board);
    BoardGUI boardGUI(board, moveGenerator, search);
    // ### end of setup ###

    // create and show qml application viewer
    QmlApplicationViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/primchess/ChessBoard.qml"));
    viewer.showExpanded();
    // make board class public in qml
    viewer.rootContext()->setContextProperty("board", &boardGUI);

    // provide also ChessPanel with board propery
    QmlApplicationViewer viewer2;
    viewer2.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer2.setMainQmlFile(QLatin1String("qml/primchess/ChessPanel.qml"));
    viewer2.rootContext()->setContextProperty("board", &boardGUI);

    return app->exec();
}
